<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryRef" :inline="true">
        <el-form-item label="考场名称" prop="roomId">
          <el-select v-model="form.roomId" placeholder="请选择">
            <el-option v-for="dict in examRoomData" :key="dict.roomId" :label="dict.roomAddress"
              :value="dict.roomId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关联考试" prop="examinationPaperId">
          <el-select v-model="form.examinationPaperId" placeholder="请选择">
            <el-option v-for="dict in relateList" :key="dict.libId" :label="dict.libTitle" :value="dict.libId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="监考人" prop="batchInvigilator">
          <el-select v-model="form.batchInvigilator" placeholder="请选择">
            <el-option v-for="dict in userList" :key="dict.userId" :label="dict.nickName" :value="dict.userId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item> -->
    <el-button color="#265DA4" :dark="isDark" icon="Search" style="margin-bottom:20px;"
    @click="handleQuery">搜索</el-button>
    <!-- <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button color="#265DA4" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:notice:add']">新增</el-button>
        </el-col>
      </el-row> -->

    <el-table v-loading="loading" center :data="examRecordList" @selection-change="handleSelectionChange">
      <el-table-column label="序号" align="left" type="index" width="100" />
      <el-table-column label="考试批次" align="left" prop="batchName" />
      <el-table-column label="考生名称" align="left" prop="userName">
      </el-table-column>
      <el-table-column label="考试试卷" align="left" prop="paperName">
      </el-table-column>
      <el-table-column label="理论考核分数" align="left" prop="paperScore">
      </el-table-column>
      <el-table-column label="单项考核分数" align="left" prop="singleScore">
        <el-table-column prop="state" label="打字"  />
        <el-table-column prop="city" label="辖区基本情况"  />
        <el-table-column prop="address" label="交通道路熟悉"  />
        <el-table-column prop="address" label="消防救援站" />
        <el-table-column prop="state" label="普通话"  />
        <el-table-column prop="city" label="警情询问和受理"  />
        <el-table-column prop="address" label="接处警系统警情受理"  />
        <el-table-column prop="address" label="接处警系统力量调度" />
        <el-table-column prop="address" label="接警平台模拟实操" />
      </el-table-column>
      <el-table-column label="总分" align="left" prop="totalScore">
      </el-table-column>
      <!-- <el-table-column label="考生信息" align="left" prop="knowStr">
        </el-table-column> -->
      <!-- <el-table-column label="操作" align="left" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-button link style="color:#265DA4;" icon="Edit" @click="handleUpdate(scope.row)"
              v-hasPermi="['system:notice:edit']">编辑</el-button>
            <el-button link style="color:#265DA4;" icon="Delete" @click="handleDelete(scope.row)"
              v-hasPermi="['system:notice:remove']">删除</el-button>
          </template>
        </el-table-column> -->
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" v-model="open" width="780px" append-to-body class="dialogClass">
      <template #title>
        <el-icon color="#fff">
          <CollectionTag />
        </el-icon>
        <span>{{ title }}</span>
      </template>
      <el-form ref="noticeRef" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="10">
            <el-form-item label="考试批次:" prop="batchName">
              <el-input v-model="form.batchName" placeholder="请输入考试批次" class="inputDeep" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="考场名称:" prop="roomId">
              <el-select v-model="form.roomId" placeholder="请选择">
                <el-option v-for="dict in examRoomData" :key="dict.roomId" :label="dict.roomName"
                  :value="dict.roomId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="岗&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;位:" prop="postId">
              <el-select v-model="form.postId" placeholder="请选择">
                <el-option v-for="dict in postList" :key="dict.dictCode" :label="dict.dictLabel"
                  :value="dict.dictCode"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="监&nbsp;考&nbsp;人:" prop="batchInvigilator">
              <el-select multiple v-model="form.batchInvigilator" placeholder="请选择">
                <el-option v-for="dict in userList" :key="dict.userId" :label="dict.nickName"
                  :value="String(dict.userId)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="考试试卷:" prop="examinationPaperId">
              <el-select v-model="form.examinationPaperId" placeholder="请选择">
                <el-option v-for="dict in relateList" :key="dict.paperId" :label="dict.paperName"
                  :value="dict.paperId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <e-col :span="24">
            <el-form-item label="考试时间:" prop="examinationOpeningHours">
              <el-date-picker v-model="form.examinationOpeningHours" value-format="YYYY-MM-DD HH:mm"
                type="datetimerange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[
                  new Date(2000, 1, 1, 0, 0, 0),
                  new Date(2000, 1, 1, 23, 59, 59),
                ]"></el-date-picker>
            </el-form-item>
          </e-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button color="#265DA4" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
  
<script setup name="Place">
import {
  examinationRecordList,

} from "@/api/examManage/examRecord.js";
import { listUser } from "@/api/system/user";
import { examinationPaperList } from "@/api/examManage/examPaper.js";
import {
  examRoomList,
} from "@/api/examRoom/examConfig";
import { listData } from "@/api/system/dict/data";
const { proxy } = getCurrentInstance();

const postList = ref([]);
const examPerList = ref([]);
const relateList = ref([]);
const examRecordList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const knowList = ref([]);
const userList = ref([]);
const examRoomData = ref([]);


const data = reactive({
  form: {
    batchName: '',
    roomId: '',
    batchInvigilator: '',
    examinationPaperId: '',
    examinationOpeningHours: '',
  },
  queryParams: {
    pageSize: 10,
    pageNum: 1,
    batchInvigilator: "",
    examinationPaperId: '',
    roomId: ''
  },
  rules: {
    batchName: [
      { required: true, message: "考试批次不能为空", trigger: "blur" },
    ],
    roomId: [
      { required: true, message: "考场名称不能为空", trigger: "blur" },
    ],
    batchInvigilator: [
      { required: true, message: "监考人不能为空", trigger: "blur" },
    ],
    examinationPaperId: [
      { required: true, message: "考试试卷不能为空", trigger: "blur" },
    ],
    examinationOpeningHours: [
      { required: true, message: "考试时间不能为空", trigger: "change" },
    ],
    postId: [
      { required: true, message: "岗位不能为空", trigger: "blur" },
    ],
  },
});

const { queryParams, form, rules } = toRefs(data);

console.log(queryParams.value, "value");
/** 查询用户列表 */
function getListUser() {
  loading.value = true;
  listUser({ pageSize: 100, }).then(res => {
    userList.value = res.rows;
  });
};
// 查询岗位
/** 查询岗位列表 */
function getPostList() {
  listData({
    pageNum: 1,
    pageSize: 100,
    dictType: "sys_post_type",
    status: "0",
  })
    .then((response) => {
      postList.value = response.rows;
    });
}
/** 查询考场列表 */
function getexamRoomList() {
  examRoomList({ pageSize: 200, }).then((response) => {
    examRoomData.value = response.rows;

  });
}
/** 查询批次列表 */
function getList() {
  loading.value = true;
  examinationRecordList(queryParams.value).then((response) => {
    examRecordList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}
/** 查询批次列表 */
function getPaperList() {
  examinationPaperList({
    pageSize: 200,
    pageNum: 1,
    paperStatus: '',
    paperType: '',
    paperName: ''
  }).then((response) => {
    relateList.value = response.rows;
  });
}
/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}
/** 表单重置 */
function reset() {
  form.value = {
  };
  proxy.resetForm("noticeRef");
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.noticeId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}
/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "新增";
}
/**修改按钮操作 */
function handleUpdate(row) {
  reset();
  console.log(row, "f");
  open.value = true;
  title.value = "编辑";
  form.value.batchId = row.batchId;
  form.value.postId = row.postId;
  form.value.batchName = row.batchName;
  form.value.roomId = row.roomId;
  form.value.batchInvigilator = row.batchInvigilator.split(",");
  form.value.examinationPaperId = row.examinationPaperId;
  form.value.examinationOpeningHours = row.examinationOpeningHours.split(",");
}
/** 提交按钮 */
function submitForm() {
  console.log(form.value, "form.value");
  proxy.$refs["noticeRef"].validate((valid) => {
    if (valid) {
      if (form.value.batchId != undefined) {
        examinationBatchEdit({
          ...form.value,
          batchInvigilator: form.value.batchInvigilator.join(","),
          examinationOpeningHours: form.value.examinationOpeningHours.join(","),
        }).then((response) => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        console.log(form.value, "form.value.");
        examinationBatchAdd({
          ...form.value,
          batchInvigilator: form.value.batchInvigilator.join(","),
          examinationOpeningHours: form.value.examinationOpeningHours.join(","),
        }).then((response) => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}
/** 删除按钮操作 */
function handleDelete(row) {
  const batchId = row.batchId;
  proxy.$modal
    .confirm('是否确认删除该数据项？')
    .then(function () {
      return examinationBatchRomove(batchId);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => { });
}

getexamRoomList()
getListUser()
getPaperList();
getList();
getPostList()
</script>
<style lang="scss" scoped>
:deep(.el-pagination.is-background .el-pager li:not(.is-disabled).is-active) {
  background-color: #265DA4 !important; //修改默认的背景色
}

.inputDeep {
  :deep(.el-input__inner) {
    width: 192px !important;
  }
}
</style>
  